package service;

import entity.Book;
import entity.Gift;
import factory.GiftFactory;
import role.Impl.User;

public class BookService {
	public static Book[] books = new Book[30];
	private User user;
	
	public BookService(){
		
	}
	
	public BookService(User user) {
		this.user = user;
	}
	
	/**
	 * 初始化图书方法
	 */
	public void initBook(){
		books[0] = new Book("1001", "java入门", 25, 30.0);
		books[1] = new Book("1002", "java高级应用", 34, 44.5);
		books[2] = new Book("1003", "java入门", 23, 34.5);
		books[3] = new Book("1004", "邓肯自传", 66, 64.0);
	}
	
	/**
	 * 判断图书存在不存在
	 */
	
	public Book isBookExist(String id){
		for (Book book : books) {
			if(book == null){
				continue;
			}
			if(book.getId().equals(id)){
				return book;
			}
		}
		return null;
	}
	
	/**
	 * 图书入库
	 * 
	 * @param book
	 * @param inNum
	 * @return
	 */
	public boolean bookIn(Book book, int inNum) {
		return user.bookIn(book, inNum);
	}

	/**
	 * 图书出库
	 * 
	 * @param book
	 * @param outNum
	 * @return
	 */
	public boolean bookOut(Book book, int outNum) {
		return user.bookOut(book, outNum);
	}

	/**
	 * 显示图书
	 * 
	 * @param book
	 * @param inNum
	 */
	public void showBook() {
		user.showBook(books);
	}

	/**
	 * 添加图书
	 * 
	 * @param book
	 * @param inNum
	 */
	public boolean addBook(Book[] books, Book book) {
		return user.addBook(books, book);
	}

	/**
	 * 结算图书
	 * 
	 * @param book
	 */
	public void checkBook(Book book) {
		user.checkBook(book);
	}

	/**
	 * 购买图书
	 * 
	 * @param book
	 * @param buyNum
	 * @return
	 */
	public Book buyBook(Book book, int buyNum) {
		return user.buyBook(book, buyNum);
	}

	/**
	 * 购买附赠品
	 * 
	 * @param giftId
	 * @return
	 */
	public Gift buyGift(int giftId) {
		return GiftFactory.getGift(giftId);
	}
}
